import 'package:flutter/material.dart';
import 'package:flutter_cookbook/ui/pages/FavoritePage.dart';
import 'package:package_info/package_info.dart';

PackageInfo packageInfo;

class MyUserWidget extends StatelessWidget {

  MyUserWidget() {
    getPackInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        //crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            flex: 1,
            child: Container(
              color: Colors.red,
              child: Center(
                child: FlutterLogo(
                  size: 120,
                ),
              ),
            )
          ),
          Expanded(
            flex: 2,
            child: Container(
              child: ListView(
                itemExtent: 50,
                physics: BouncingScrollPhysics(),
                children: [
                  GestureDetector(
                    onTap: () {
                      Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                        return FavoritePage();
                      }));
                    },

                    child: Container(
                      color: Colors.transparent,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Expanded(
                              flex: 1,
                              child: Center(
                                child: Icon(Icons.arrow_left),
                              )),
                          Expanded(
                              flex: 3,
                              child: Center(
                                child: Text(
                                  "我的收藏",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18
                                  ),
                                ),
                              )
                          ),
                          Expanded(
                              flex: 1,
                              child: Center(
                                child: Icon(Icons.arrow_right),
                              )
                          )
                        ],
                      ),
                    ),
                  ),
                  /*GestureDetector(
                    onTap: () {

                    },

                    child: Container(
                      color: Colors.transparent,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Expanded(
                              flex: 1,
                              child: Center(
                                child: Icon(Icons.arrow_left),
                              )),
                          Expanded(
                              flex: 3,
                              child: Center(
                                child: Text(
                                  "和我联系",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18
                                  ),
                                ),
                              )
                          ),
                          Expanded(
                              flex: 1,
                              child: Center(
                                child: Icon(Icons.arrow_right),
                              )
                          )
                        ],
                      ),
                    ),
                  ),*/
                  GestureDetector(
                    onTap: () {
                      showAboutDialog(context);
                    },

                    child: Container(
                      color: Colors.transparent,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Expanded(
                              flex: 1,
                              child: Center(
                                child: Icon(Icons.arrow_left),
                              )),
                          Expanded(
                              flex: 3,
                              child: Center(
                                child: Text(
                                  "关于软件",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18
                                  ),
                                ),
                              )
                          ),
                          Expanded(
                              flex: 1,
                              child: Center(
                                child: Icon(Icons.arrow_right),
                              )
                          )
                        ],
                      ),
                    ),
                  )
                ],
                shrinkWrap: true,
              ),
              margin: EdgeInsets.only(top: 32),
            )
          )

        ],
      ),
    );
  }

  Future<bool> showAboutDialog(BuildContext context) {
    String version = "未知";
    if (packageInfo != null) {
      version = packageInfo.version;
    }

    return showDialog(context: context, builder: (context) {
      return AlertDialog(
        title: Row(
          children: [
            FlutterLogo(
              size: 20,
            ),
            Text("关于菜谱")
          ],
        ),
        content: Text("版本：" + version),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Text("确定")
          )
        ],
      );
    });
  }

  void getPackInfo() async {
    packageInfo = await PackageInfo.fromPlatform();
  }
}